package com.lepu.app.fun.my;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebView;
import android.widget.ScrollView;
import android.widget.TextView;

import com.app.utils.Setting;
import com.app.utils.Utils;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.AsyncRequest;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.core.lib.widget.CircularImageView;
import com.lepu.app.fun.chat.bean.BeanDoctorMyDetail;
import com.lepu.app.fun.chat.business.DoctorManager;
import com.lepu.app.fun.my.bean.BeanMyActivityDetail;
import com.lepu.app.widget.CustomTopBarNew;
import com.lepu.app.widget.CustomTopBarNew.OnTopbarNewLeftLayoutListener;
import com.lepu.pasm.R;

public class MyLectureDoctorInfoActivity extends BaseFragmentActivity implements
		OnTopbarNewLeftLayoutListener,AsyncRequest {

	public static final String REQUEST_DATA = "request_data";

	BeanDoctorMyDetail mBeanDoctorMyDetail;

	WebView mWebView;
	ScrollView mScrollView;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.my_lecture_doctor_info_activity);

		init();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	/**
	 * 添加页面动画，需要重写这个方法，
	 */
	@Override
	public void onBackPressed() {
		finish(true);
	}
	
	@Override
	public void onTopbarLeftLayoutSelected() {
		finish(true);
	}


	/**
	 * 初始化方法
	 */
	private void init() {
		// topbar
		CustomTopBarNew topbar = (CustomTopBarNew) findViewById(R.id.topbar);
		topbar.setTopbarTitle("医生简介");
		topbar.setonTopbarNewLeftLayoutListener(this);

		String DoctorID = getIntent().getStringExtra("DoctorID");

		mWebView = (WebView) findViewById(R.id.webView);
		mScrollView = (ScrollView) findViewById(R.id.scrollView);
		Utils.initWebViewSettings(mWebView, true);

		mScrollView.setVisibility(View.GONE);

		showProgressDialog();
		DoctorManager.getInstance().requestDoctorDetail(this, DoctorID);
	}

	private void initData()
	{
		mScrollView.setVisibility(View.VISIBLE);

		CircularImageView accountIconImageView = (CircularImageView) findViewById(R.id.accountIconImageView);
		accountIconImageView
				.setImageResource(R.drawable.chat_doctor_icon_default);

		UniversalImageLoadTool.disPlay(
				Setting.getImageUrl(mBeanDoctorMyDetail.Avatar),
				accountIconImageView, R.drawable.chat_doctor_icon_default);

		TextView hospitalNameTextView = (TextView) findViewById(R.id.hospitalNameTextView);
		TextView nameTextView = (TextView) findViewById(R.id.nameTextView);
		TextView zhuZhiTextView = (TextView) findViewById(R.id.zhuZhiTextView);
		TextView goodAtTextView = (TextView) findViewById(R.id.goodAtTextView);

		hospitalNameTextView.setText(mBeanDoctorMyDetail.HospitalName);
		nameTextView.setText(mBeanDoctorMyDetail.DoctorName);
		zhuZhiTextView.setText(mBeanDoctorMyDetail.MedicalJobTitle+"  "+mBeanDoctorMyDetail.JobTitle);
		goodAtTextView.setText("擅长：" + mBeanDoctorMyDetail.Skill);

		mWebView.loadData(mBeanDoctorMyDetail.Resume,
				"text/html; charset=UTF-8", null);
	}

	@Override
	public void RequestComplete(Object object, Object data) {
		if (object.equals(REQUEST_DATA)) {
			hideProgressDialog();

			mBeanDoctorMyDetail = BeanDoctorMyDetail
					.parseDetailInfo((String) data);
			if (mBeanDoctorMyDetail != null
					&& !TextUtils.isEmpty(mBeanDoctorMyDetail.DoctorName)) {
				initData();
			}
		}
	}

	@Override
	public void RequestError(Object object, int errorId, String data) {
		if (object.equals(REQUEST_DATA)) {
			hideProgressDialog();
		}
	}
}
